#include "HikCamera.hpp"

int main() {
    auto camera = qd::Device::HikCamera();
    camera.set_func_get_time([]() { return std::chrono::system_clock::now(); });

    // 用于计算FPS的变量
    int frame_count = 0;
    double fps = 0.0;
    auto last_time = std::chrono::steady_clock::now();

    while (true) {
        cv::Mat img = camera.get_cv_img();
        if (img.empty())
            continue;

        // 帧数累加
        frame_count++;

        // 每隔1秒更新一次FPS
        auto now = std::chrono::steady_clock::now();
        auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - last_time).count();
        if (elapsed >= 1) {
            fps = frame_count / static_cast<double>(elapsed);
            frame_count = 0;
            last_time = now;
        }

        // 在图像上显示FPS
        cv::putText(
            img,
            "FPS: " + std::to_string(static_cast<int>(fps)),
            cv::Point(20, 40),
            cv::FONT_HERSHEY_SIMPLEX,
            1.0,
            cv::Scalar(0, 255, 0),
            2
        );

        cv::imshow("HIK Camera", img);
        // std::cout << "Current FPS: " << fps << std::endl;

        // 按 ESC 键退出
        if (cv::waitKey(1) == 27)
            break;
    }

    return 0;
}